const num = 10;
// 十进制转换为二进制
function tenToTwo(num) {
  const stack = [];
  let temp = num;
  while (temp > 0) {
    const y = temp % 2;
    stack.push(y);
    temp = Math.floor(temp / 2);
  }
  let i = stack.length;
  let str = "";
  while (i) {
    str = str + stack.pop();
    i--;
  }

  return str;
}
const e = tenToTwo(10);

// 有效括号
// (())(())
function validateKuo(str) {
  const stack = [];
  for (let i = 0; i < str.length; i++) {
    if (str[i] === "(") {
      stack.push(str[i]);
    }
    if (str[i] === ")") {
      if (stack.length) {
        stack.push(str[i]);
      } else {
        stack.pop();
      }
    }
  }
  if (stack.length) {
    return false;
  }
  return true;
}
console.log(validateKuo("(())(())"));
